#include <stdio.h>
#include <math.h>
#include <string.h>

#define  M  30e-23

int add(int x, int y);
int sub(int x, int y);
int mul(int x, int y);
int div(int x, int y);
int mypow(int x, int y);


int main(int argc, char const *argv[])
{
/**** 计算从1+2+3+4...+10 之和 ****/
#if 0 
    int sum;
    for (int i = 1; i <= 10; i++)
    {
        sum += i;
        printf("i=%d\n",i);
        
    }
    printf("sum=%d\n",sum);
#endif

/**** 使用二进制、八进制、十进制、十六进制表示一个数并使用十进制输出 ****/
#if 0 
    int a = 0b1010;
    int b = 01010;
    int c = 1010;
    int d = 0x1010;

    printf("a=%d\n",a);
    printf("b=%d\n",b);
    printf("c=%d\n",c);
    printf("d=%d\n",d);

#endif

/**** 使用sizeof运算符计算每一种数据类型的占用字节数 ****/
#if 0
    printf("sizeof(char              )=%d\n",sizeof(char              ));
    printf("sizeof(unsigned char     )=%d\n",sizeof(unsigned char     ));
    printf("sizeof(short             )=%d\n",sizeof(short             ));
    printf("sizeof(unsigned short    )=%d\n",sizeof(unsigned short    ));
    printf("sizeof(int               )=%d\n",sizeof(int               ));
    printf("sizeof(unsigned int      )=%d\n",sizeof(unsigned int      ));
    printf("sizeof(long              )=%d\n",sizeof(long              ));
    printf("sizeof(unsigned long     )=%d\n",sizeof(unsigned long     ));
    printf("sizeof(long int          )=%d\n",sizeof(long int          ));
    printf("sizeof(unsigned long int )=%d\n",sizeof(unsigned long int ));
    printf("sizeof(long long         )=%d\n",sizeof(long long         ));
    printf("sizeof(unsigned long long)=%d\n",sizeof(unsigned long long));
    printf("sizeof(float             )=%d\n",sizeof(float             ));
    printf("sizeof(double            )=%d\n",sizeof(double            ));
    printf("sizeof(long doubue       )=%d\n",sizeof(long double       ));
#endif

/**** 一个水分子的质量约为3.0*10-23g，1夸脱水大约有950g，编写一个程序，要求输入水的夸脱数，然后显示这么多水中包含多少水分子 ****/
#if 0
    int i;
    printf("请输入水的夸脱数>:");
    scanf("%d",&i);
    printf("i=%d\n",i);

    float sum = i*950/M;
    printf("%d 夸脱水中有%e 个水分子\n",i,sum);

#endif

/**** 算数运算符 ****/
#if 0
    int a = 15,b = 9,c;
    float x = 15,y = 8,z;

    c = a + b;
    printf("c=%d\n",c);

    c = a - b;
    printf("c=%d\n",c);

    c = a * b;
    printf("c=%d\n",c);

    c = a / b;
    printf("c=%d\n",c);

    c = a % b;
    printf("c=%d\n",c);

    z = x + y;
    printf("z=%f\n",z);

    z = x - y;
    printf("z=%f\n",z);

    z = x * y;
    printf("z=%f\n",z);

    z = x / y;
    printf("z=%f\n",z);

#endif

/**** 赋值复合运算符 ****/
#if 0
    int a = 10,b = 8;
    a += b;
    printf("a=%d\n",a);

    a = 10,b = 8;
    a -= b;
    printf("a=%d\n",a);

    a = 10,b = 8;
    a *= b;
    printf("a=%d\n",a);

    a = 10,b = 8;
    a /= b;
    printf("a=%d\n",a);

    a = 10,b = 8;
    a %= b;
    printf("a=%d\n",a);
    a = 10,b = 8;
    a &= b;
    printf("a=%d\n",a);

    a = 10,b = 8;
    a |= b;
    printf("a=%d\n",a);

    a = 10,b = 8;
    a ^= b;
    printf("a=%d\n",a);

    a = 10,b = 8;
    a <<= b;
    printf("a=%d\n",a);

    a = 10,b = 8;
    a >>= b;
    printf("a=%d\n",a);

#endif

/**** 三目运算符 ****/
#if 0
    int a,b,c;
    int max,min;
    printf("请输入三个整数>:");
    scanf("%d%d%d",&a,&b,&c);
    printf("a=%d,b=%d,c=%d\n",a,b,c);

    max = a>b?a:b;
    max = max>c?max:c;
    printf("max=%d\n",max);

    min = a<b?a:b;
    min = min<c?min:c;
    printf("min=%d\n",min);

#endif

/**** 字符输出putchar ****/
#if 0
  //先赋值，在输出
    int a = 65;
    int a2 = 'A';
    int a3 = 65 + ' ';

    putchar(a);
    putchar(a2);
    putchar(a3);

  //直接输出
    putchar('\n');
    putchar(65);
    putchar('a'-' ');
    putchar('A'+' ');

#endif

/**** 1.使用printf函数输出 ****/
#if 0
    int num = 571;
    char a ='A';
    float nun = 3.1415926;

    printf("hello word\n");
    int x=10,y=20,z=30;
    printf("x=%d\n",x);
    printf("x=%d,y=%d,z=%d\n",x,y,z);

    printf("num=%d\n",num);
    printf("num=%x\n",num);
    printf("num=%X\n",num);
    printf("num=%u\n",num);
    printf("a=%c\n",a);
    printf("%s\n","goodbye");

    printf("nun=%e\n",nun);
    printf("nun=%E\n",nun);
    printf("nun=%f\n",nun);
    printf("nun=%g\n",nun);

    printf("num=%p\n",num);
    printf("%%");

#endif

/**** 2.使用printf函数输出 ****/
#if 0
    int num = 571;
    printf("num=%d\n",num);
    printf("num=%5d\n",num);    //输出5个宽度的num，num占3个宽度，左补两个空格
    printf("num=%05d\n",num);    //输出5个宽度的num，num占3个宽度，左补两个0
    printf("num=%2d\n",num);    //输出>设置的2个宽度，按照实际输出

    printf("num=%od\n",num);
    printf("num=%xd\n",num);
    printf("num=%#od\n",num);
    printf("num=%#xd\n",num);

    float n = 3.1415926;
    printf("n=%f\n",n);
    printf("n=%.2f\n",n);
    printf("n=%.3f\n",n);   //(四舍五入)

    int a = -123;
    printf("num=%+d\n",num);    //将num加上正号输出
    printf("a=%+d\n",a);

#endif

/**** 字符输入getchar ****/
#if 0
/*
    char ch;
    ch = getchar(); //只能从键盘读取一个字符
    printf("ch=%c\n",ch);
*/
  //使用getchar从键盘读取一个（小写或者大写）字符，输出他的（小写或者大写）字符和 ASCII码
    char num;
    while(1)
    {
        num = getchar();
        if((num<='Z') && (num>='A'))
        {
            num += ' ';
            scanf("%*[^\n]");
            scanf("%*c");  
        }
        else if((num<='z') && (num>='a'))
        {
            num -= ' ';  
            scanf("%*[^\n]");
            scanf("%*c");
        }
        printf("num=%c\n",num);
        break;
    }  

#endif

/**** 输入三角形边长，求面积 ****/
#if 0
    int a,b,c,S;
    float ares;
    printf("请输入三角形的三边边长>:");
    scanf("%d%d%d",&a,&b,&c);
    printf("a=%d,b=%d,c=%d\n",a,b,c);

    if((a+b>c) && (a+c>b) && (b+c>a))
    {
        S = (a+b+c)/2;
        ares = sqrt(S*(S-a)*(S-b)*(S-c));
        printf("S=%d\n",S);
        printf("ares=%f\n",ares);
    }
    else 
    {
        printf("不满足三角形的三边关系，请重新输入\n");
    }

#endif

/**** 从键盘输入a、b、c的值，求方程的根 ****/
#if 0
    int a,b,c;
    int x,x1,x2;

    printf("请输入a b c 的值>:");
    scanf("%d%d%d",&a,&b,&c);
    printf("a=%d,b=%d,c=%d\n",a,b,c);

    if((b*b-(4*a*c))>0)
    {
        x = (-b) + (sqrt(b*b-(4*a*c)));
        x1 = x/(2*a);

        x = (-b) - (sqrt(b*b-(4*a*c)));
        x2 = x/(2*a);
        printf("方程的根为:%d,%d",x1,x2);
    }
    else
    {
        printf("方程无实根,请重新输入\n");
    }

#endif

/**** 用if-else语句实现，键盘输入2个整数，程序中使用=、> 或< 符号判断其大小 ****/
#if 0
    int a,b;
    printf("请输入两个整数>:");
    scanf("%d%d",&a,&b);
    printf("a=%d,b=%d\n",a,b);

    if(a>b)
    {
        printf("a > b\n");
        printf("%d > %d\n",a,b);

    }
    else if(a<b)
    {
        printf("a < b\n");
        printf("%d < %d\n",a,b);

    }
    else
    {
        printf("a = b\n");
        printf("%d = %d\n",a,b);

    }

#endif

/**** 键盘输入ABCDE其中一个字母,然后输出A表示90分以上，B表示80到90分，
 *    C表示70到80分，D表示60到70分，E表示60分以下  ****/
#if 0
    int ch;
    printf("请输入成绩级别(A/B/C/D/E)>:");
//第一种方式：
   // ch = getchar();
//第二种方式：
    scanf("%c",&ch);
    
    switch (ch)
    {
    case 'A': printf("90<成绩<=100"); break;
    case 'B': printf("80<=成绩<90"); break;
    case 'C': printf("70<=成绩<80"); break;
    case 'D': printf("60<=成绩<70"); break;
    case 'E': printf("0<=成绩<60"); break; 
    default: printf("输入的成绩级别错误,请重新输入"); break;
    }

#endif

/**** 用for语句计算1+2+3+4+…+100 之和 ****/
#if 0
    int sum;
    for (int i = 0; i <= 100; i++)
    {
        sum += i;
    }
    printf("sum=%d\n",sum);
    
#endif

/**** 用for循环嵌套语句实现如下图案, 5行5列的*  ****/
#if 0

    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
    
    
#endif

/**** 用for循环嵌套语句实现如下图案, 5行递增的*  ****/
#if 0
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < i+1; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
        
    
#endif

/**** 用for循环嵌套语句实现如下图案, 5行递减的*  ****/
#if 0
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5-i; j++)
        {
            printf("* ");
        }
        printf("\n");
    }

        
    
#endif

/**** 用for循环嵌套语句实现如下图案, 5行递减的* 接着运行4行递增*  ****/
#if 0
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5-i; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
    for (int i = 1; i < 5; i++)
    {
        for (int j = 0; j < i+1; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
    
#endif

/**** 用while语句实现 1+2+3+…+100 之和  ****/
#if 0
//int sum,i;不设置初始值，sum和i的值为随机数，不会是 0
    int sum=0,i=0;
    
    while(i!=100)
    {   
        i++; 
        sum += i;
    }
    printf("sum=%d\n",sum);
    
#endif


/**** 使用do while语句实现 1+2+3+…+100 之和  ****/
#if 0
    int sum=0,i=0;
    do
    {
        i++;
        sum += i;
    } while (i!=100);
    printf("sum=%d\n",sum);

#endif

/**** 用goto语句实现 1+2+3+…+100 之和  ****/
#if 0
    int sum=0,i=0;
le: 
    i++;
    sum += i;
    while(i!=100)   //可以用for语句、if语句
    {
        goto le;
    }
    printf("sum=%d\n",sum);

#endif

/**** continue和break语句来模拟时间运行并计算一天一共有多少秒  ****/
#if 0
    int sec=0,min=0,hour=0;
    int count_sec=0;
    while(1)
    {
        printf("HH:MM:SS ->%02d:%02d:%02d\n",hour,min,sec);
        sec++;
        count_sec++;
        if (sec<60)
        {
            continue;
        }
        min++;
        sec=0;
        if(min<60)
        {
            continue;
        }
        hour++;
        min=0;
        if(hour<24)
        {
            continue;
        }
        hour=0;
        break;

    }
    printf("count_sec=%d\n",count_sec);
    
#endif

/**** 输出100以内的素数  ****/
#if 0

    for (int i = 2; i < 100; i++)
    {
        if (i == 2)
        {
            printf("%d ", i);
        }
        for (int j = 2; j < i; j++)
        {
            if (i % j == 0)
            {
                break;
            }
            if (j > i / 2)
            {
                printf("%d ", i);
                break;
            }
        }
    }
    printf("\n");

#endif

/**** 计算任意2个数的最大公约数和最小公倍数  ****/
#if 0
    int n,m,t,p,r;
    printf("请输入两个整数>:");
    scanf("%d%d",&n,&m);
    printf("n=%d,m=%d\n",n,m);

    if (n<m)
    {
        t=n;
        n=m;
        m=n;
    }
    p=n*m;

    while(m!=0)
    {
        r=n%m;
        n=m;
        m=r;
    }
    printf("最大公约数为:%d",n);
    printf("最小公倍数为:%d",p/n);

#endif

/**** 输出一个9x9的乘法表  ****/
#if 0
   
   for (int i = 1; i < 10; i++)
   {
    for (int j = 1; j < i+1; j++)
    {
        printf("%d x %d =%-2d  ",j,i,i*j);
    }
    printf("\n");
   }

#endif

/**** 循环输出26个字母  ****/
#if 0
   
   for (int i = 0; i < 5; i++)
   {
    for (int j = 65; j < 91; j++)
    {
        putchar(j);
    }
    printf("\n");
   }
     
#endif

/**** 从键盘输入10个数（int类型参数）存入一维数组中，并且逆序输出  ****/
#if 0
    int a[10]={0};
    int x;
    printf("请输入10个数>:");
    for (int i = 0; i < 10; i++)
    {
        scanf("%d",&a[i]);
    }
    printf("\n");
    printf("数组为：");
    for (int i = 0; i < 10; i++)
    {
        printf("%d ",a[i]);
    }
    printf("\n");
    printf("交换后数组为：");
    for (int i = 0; i < 5; i++)
    {
        x=a[i];
        a[i]=a[10-1-i];
        a[10-1-i]=x;
    }
    
    for (int i = 0; i < 10; i++)
    {
        printf("%d ",a[i]);
    }
    
    
#endif

/**** 从键盘输入10个数（int类型参数）存入一维数组中，找出这个10个数中最大的数并输出  ****/
#if 0
    int a[10]={0};
    int t;
    printf("请输入10个数>:");
    for (int i = 0; i < 10; i++)
    {
        scanf("%d",&a[i]);
    }
    printf("数组内容为:");
    for (int i = 0; i < 10; i++)
    {
        printf("%d ",a[i]);
    }
    printf("\n");

    for (int i = 0; i < 10-1; i++)  //比较次数9次
    {
        if(a[i] > a[i+1])
        {
            t=a[i];
            a[i]=a[i+1];
            a[i+1]=t;


        }
        
    }
    printf("最大值为：%d\n",a[10-1]); //输出最右边的值
    

    
    
    
#endif

/**** 从键盘输入10个int类型参数，存放到数组中，进行从大到小排序  ****/
#if 0
    int a[10]={0};
    int t;
    for (int i = 0; i < 10; i++)
    {
        printf("请输入第%d个数>:",i+1);
        scanf("%d",&a[i]);
    }

    printf("数组内容为:");
    for (int i = 0; i < 10; i++)
    {
        printf("%d ",a[i]);
    }
    printf("\n");
    
    for (int i = 0; i < 10-1; i++)
    {
        for (int j = 0; j < 10-1-i; j++)
        {
            if(a[j] > a[j+1])
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
        
    }
    
    printf("从小到大为：");
    for (int i = 0; i < 10; i++)
    {
        printf("%d ",a[i]);
    }
    
    

#endif  

/**** 从键盘输入10个int类型参数，存放到数组中，进行从大到小排序  ****/
#if 0
    int a[10]={0};
    int k,t;
    for (int i = 0; i < 10; i++)
    {
        printf("请输入第%d个整数",i+1);
        scanf("%d",&a[i]);
    }

    printf("数组内容为：");
    for (int i = 0; i < 10; i++)
    {
        printf("%d ",a[i]);
    }
    
    for (int i = 0; i < 10-1; i++)
    {
        k = 0;
        for (int j = 0; j < 10-1-i; j++)
        {
            if(a[k] > a[j+1])
            {
                k = j+1;
            }
        }
        if(k!=10-1-i)
        {
            t=a[k];
            a[k]=a[10-1-i];
            a[10-1-i]=t;
        }
        
    }
    printf("\n");
    printf("排序内容为：");
   
    for (int i = 0; i < 10; i++)
    {
        printf("%d ",a[i]);
    }

#endif 

/**** 斐波那契数列指的是这样一个数列 
 * 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233，377，610，987，1597，2584，4181，6765，10946，17711，28657，46368........  
 * 计算5年后有多少只兔子, 5年是60个月, 输出前60个月的兔子 ****/
#if 0
    long long a[60]={0};
    for (int i = 0; i < 60; i++)
    {
        if(i<2)
        {
            a[i]=1;
        }
        else
        {
            a[i]=a[i-1]+a[i-2];
        }
    }

    printf("\n");
    for (int i = 0; i < 60; i++)
    {
        printf("第%d月有兔子%lld\n",i+1,a[i]);
    }
    
    

#endif 

/**** 从键盘输入一个3行4列的整型数组并且打印出来  ****/
#if 0
    int a[3][4]={};
    printf("请输入整数>:");
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            scanf("%d",&a[i][j]);
        }
        
    }
    
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            printf("%2d ",a[i][j]);
        }
        printf("\n");
    }
    
#endif
 
/**** 输出杨辉三角的前10行  ****/
#if 0
    int a[10][10]={};
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10-1-i; j++)
        {
            printf("  ");
        }
        
        for (int j = 0; j < i+1; j++)
        {
            if((j==0) || (j==i))
            {
                a[i][j]=1;
            }
            else
            {
                a[i][j] =a[i-1][j]+a[i-1][j-1];
            }

            printf("%3d ",a[i][j]);
        }
        printf("\n");
    }

#endif 

/**** 使用二维字符数组输出 ( Mon , Tue , Wed , Thurs, Fri, Sat, Sun)  ****/
#if 0

    char a[][6]={"Mon","Tue","Wed","Thurs","Fri","Sat","Sun"};
    for (int i = 0; i < sizeof(a)/sizeof(a[0]); i++)
    {
        printf("a[%d]=%s \n",i,a[i]);
    }   

#endif 

/**** 输入一个字符串，然后将其逆序输出  ****/
#if 0

    char a[100]={0};
    int j=0;
    printf("请输入一个字符串>:");
    scanf("%s",a);
    printf("字符串为：%s \n",a);

    while(a[j]!='\0')
    {
        j++;
    }
    char t;
    for (int i = 0; i < j/2; i++)
    {
       t=a[i];
       a[i]=a[j-1-i];
       a[j-1-i]=t; 
    }
    printf("倒序字符串为：%s\n",a);
    
    

#endif 

/**** 编程使用strcat函数实现两个字符串的拼接功能  ****/
#if 0

    char a1[100]={0};
    char a2[100]={0};
    int j=0,t=0;
    printf("请输入第一个字符串>:");  
    scanf("%s",a1);
    printf("请输入第二个字符串>:");
    scanf("%s",a2);

    printf("字符串1为:%s \n",a1);
    printf("字符串2为:%s \n",a2);
    //strcat(a1,a2);
    while(a1[j]!='\0')
    {
        j++;
    }

    while((a1[j++]=a2[t++]) !='\0');
/*  while(1)
    {
        a1[j] = a2[t];
        if(a1[j]==0)
        {
            break;
        }
        j++;
        t++;
    }
*/
    printf("字符串1为:%s \n",a1);
    printf("字符串2为:%s \n",a2);
    
    

#endif

/**** 编程使用strcpy函数实现两个字符串的复制功能  ****/
#if 0

    char a1[100]={0};
    char a2[100]={0};
    int j=0,t=0;
    printf("请输入第一个字符串>:");  
    scanf("%s",a1);
    printf("请输入第二个字符串>:");
    scanf("%s",a2);

    printf("字符串1为:%s \n",a1);
    printf("字符串2为:%s \n",a2);
    //strcpy(a1,a2);

    while((a1[j++]=a2[t++]) !='\0');
    /*while(1)
    {
        a1[j] = a2[t];
        if(a1[j]==0)
        {
            break;
        }
        j++;
        t++;
    }*/

    printf("字符串1为:%s \n",a1);
    printf("字符串2为:%s \n",a2);
    
    

#endif

/**** strncpy 可以复制精确的字节数  ****/
#if 0

    char a1[100]={0};
    char a2[100]={0};
    int j=0,t=0;
    printf("请输入第一个字符串>:");  
    scanf("%s",a1);
    printf("请输入第二个字符串>:");
    scanf("%s",a2);

    printf("字符串1为:%s \n",a1);
    printf("字符串2为:%s \n",a2);
    strncpy(a1,a2,3);

    printf("字符串1为:%s \n",a1);
    printf("字符串2为:%s \n",a2);
    
    

#endif

/**** 使用strcmp函数比较两个字符串的大小关系  ****/
#if 0

    char a1[100]={0};
    char a2[100]={0};
    int j=0;
    printf("请输入第一个字符串>:");  
    scanf("%s",a1);
    printf("请输入第二个字符串>:");
    scanf("%s",a2);

    printf("字符串1为:%s \n",a1);
    printf("字符串2为:%s \n",a2);

    //j  = strcmp(a1,a2);

    while(a1[j]==a2[j] && a1[j]!='\0')
    {
        j++;
    }   
    if (a1[j]>a2[j])
    {
        printf("%s > %s \n",a1,a2);
    }
    else if (a1[j]<a2[j])
    {
        printf("%s < %s \n",a1,a2);

    }
    else 
    {
        printf("%s = %s \n",a1,a2);
    }

#endif

/**** 使用strcmp函数对输入的数据进行识别  ****/
#if 0

    char a[100]={0};
    int j=0;
    printf("请选择(yes/no)>:");  
    scanf("%s",a);

    if (strcmp(a,"no") == 0)
    {
        printf("你的选择是:no \n");
    }
    else if (strcmp(a,"yes") == 0)
    {
        printf("你的选择是:yes \n");
    }
    else
    {
        printf("你的选择错误，请重新输入 \n");
    }

#endif

/**** 使用strncmp函数比较输入选项是yes/no   ****/
#if 0

    char a[100]={0};
    int j=0;
    printf("请选择(yes/no)>:");  
    scanf("%s",a);

    if (strncmp(a,"no",1) == 0)
    {
        printf("你的选择是:no \n");
    }
    else if (strncmp(a,"yes",1) == 0)
    {
        printf("你的选择是:yes \n");
    }
    else
    {
        printf("你的选择错误，请重新输入 \n");
    }

#endif

/**** 输入一个字符串使用strlen函数计算字符串的长度  ****/
#if 0

    char a[100]={0};
    char a1[10]={'A','\0','B','C','\0','D'};
    char a2[]="\t\v\\\0will\n";
    char a3[]="\x69\082\n";
    printf("请输入一个字符串>:");  
    scanf("%s",a);
    printf("strlen(a)=%d\n",strlen(a));

    printf("strlen(a1)=%d\n",strlen(a1));
    printf("strlen(a2)=%d\n",strlen(a2));
    printf("strlen(a3)=%d\n",strlen(a3));

    printf("a3[0]=%#x\n",a2[0]);
    printf("a3[1]=%d\n",a2[1]);

#endif

/**** 使用自己的代码实现strlen函数实的功能, 不能使用strlen函数  ****/
#if 0

    char a[100]={0};
    int j=0;
    printf("请输入一个字符串>:");  
    scanf("%s",a);
    //printf("strlen(a)=%d\n",strlen(a));
    while(a[j]!='\0')
    {
        j++;
    }
    printf("a=%d\n",j);

#endif

/**** 分别输出char , short ,int , long , float , double 类型的变量地址  ****/
#if 0

    char   a = 10;
    short  b = 10;
    int    c = 10;
    long   d = 10;
    float  e = 10.1;
    double f = 10.1;

    printf("&a=%p\n",&a);
    printf("&b=%p\n",&b);
    printf("&c=%p\n",&c);
    printf("&d=%p\n",&d);
    printf("&e=%p\n",&e);
    printf("&f=%p\n",&f);


  //直接访问
    printf("a=%d\n",a);
    printf("b=%d\n",b);
    printf("c=%d\n",c);
    printf("d=%d\n",d);
    printf("e=%f\n",e);
    printf("f=%f\n",f);
//间接访问
    printf("*&a=%d\n",*(&a));
    printf("*&b=%d\n",*(&b));
    printf("*&c=%d\n",*(&c));
    printf("*&d=%d\n",*(&d));
    printf("*&e=%f\n",*(&e));
    printf("*&f=%f\n",*(&f));

#endif

/****  先定义2个整型变量，再定义2个指针变量，分别指向这两个整型变量，通过访问指针变量，可以找到它们所指向的变量，从而得到这些变量的值  ****/
#if 0

    int x=10,y=20;
    int *pa,*pb;
    pa=&x;
    pb=&y;

    printf("x=%d\n",x);
    printf("y=%d\n",y);
    printf("&x=%p\n",&x);
    printf("&y=%p\n",&y);
    printf("pa=%p\n",pa);
    printf("pb=%p\n",pb);

    printf("*pa=%d\n",*pa);
    printf("*pb=%d\n",*pb);
    printf("&pa=%p\n",&pa);
    printf("&pb=%p\n",&pb);

#endif

/****  分别计算char short int long , long int , long long, float , double, long double 类型的指针++ 运算的值  
 *     指针++ 运算是按照数据类型进行++ 运算，与64位/32位（8字节/4字节）无关
 *     指针的地址与系统相关，与数据类型无关****/
#if 0
    char        a = 10;
    short       b = 10;
    int         c = 10;
    long        d = 10;
    long int    e = 10;
    long long   f = 10;
    float       g = 10.1;
    double      h = 10.1;
    long double i = 10.1;

    char        *pa = &a;
    short       *pb = &b;
    int         *pc = &c;
    long        *pd = &d;
    long int    *pe = &e;
    long long   *pf = &f;
    float       *pg = &g;
    double      *ph = &h;
    long double *pi = &i;

    printf("&a=%p\n",&a);
    printf("&b=%p\n",&b);
    printf("&c=%p\n",&c);
    printf("&d=%p\n",&d);
    printf("&e=%p\n",&e);
    printf("&f=%p\n",&f);
    printf("&g=%p\n",&g);
    printf("&h=%p\n",&h);
    printf("&i=%p\n",&i);

    printf("sizeof(char         )=%p\n",sizeof(char));
    printf("sizeof(char *       )=%p\n",sizeof(char *));
    printf("sizeof(pa           )=%p\n",sizeof(pa));

    printf("sizeof(short        )=%p\n",sizeof(short));
    printf("sizeof(short *      )=%p\n",sizeof(short *));
    printf("sizeof(pb           )=%p\n",sizeof(pb));

    printf("sizeof(int          )=%p\n",sizeof(int));
    printf("sizeof(int *        )=%p\n",sizeof(int *));
    printf("sizeof(pc           )=%p\n",sizeof(pc));

    printf("sizeof(long         )=%p\n",sizeof(long));
    printf("sizeof(long *       )=%p\n",sizeof(long *));
    printf("sizeof(pd           )=%p\n",sizeof(pd));

    printf("sizeof(long int     )=%p\n",sizeof(long int));
    printf("sizeof(long int *   )=%p\n",sizeof(long int *));
    printf("sizeof(pe           )=%p\n",sizeof(pe));

    printf("sizeof(long long    )=%p\n",sizeof(long long));
    printf("sizeof(long long *  )=%p\n",sizeof(long long *));
    printf("sizeof(pf           )=%p\n",sizeof(pf));

    printf("sizeof(float        )=%p\n",sizeof(float));
    printf("sizeof(float *      )=%p\n",sizeof(float *));
    printf("sizeof(pg           )=%p\n",sizeof(pg));

    printf("sizeof(double       )=%p\n",sizeof(double));
    printf("sizeof(double *     )=%p\n",sizeof(double *));
    printf("sizeof(ph           )=%p\n",sizeof(ph));

    printf("sizeof(long double  )=%p\n",sizeof(long double));
    printf("sizeof(long double *)=%p\n",sizeof(long double *));
    printf("sizeof(pi           )=%p\n",sizeof(pi));

    printf("pa=%p\n",pa);
    pa++;
    printf("pa=%p\n",pa);

    printf("pb=%p\n",pb);
    pb++;
    printf("pb=%p\n",pb);

    printf("pc=%p\n",pc);
    pc++;
    printf("pc=%p\n",pc);

    printf("pd=%p\n",pd);
    pd++;
    printf("pd=%p\n",pd);

    printf("pe=%p\n",pe);
    pe++;
    printf("pe=%p\n",pe);

    printf("pf=%p\n",pf);
    pf++;
    printf("pf=%p\n",pf);

    printf("pg=%p\n",pg);
    pg++;
    printf("pg=%p\n",pg);

    printf("ph=%p\n",ph);
    ph++;
    printf("ph=%p\n",ph);

    printf("pi=%p\n",pi);
    pi++;
    printf("pi=%p\n",pi);

#endif

/**** 计算两个int类型指针相减的值  ****/
#if 0

    int a[5];
    int *pa =&a[0];
    int *pb = &a[3];
    printf("pa=%p\n",pa);
    printf("pb=%p\n",pb);
    printf("pb-pa =%d\n",pb-pa);

#endif

/**** 数组成员与数组的地址
 *    数组名是一个地址常量，是起始地址，也是第一个元素的地址  ****/
#if 0

    int a[5]={1,2,3,4,5};

    printf("&a[0]=%p\n",&a[0]);
    printf("&a[1]=%p\n",&a[1]);
    printf("&a[2]=%p\n",&a[2]);
    printf("&a[3]=%p\n",&a[3]);
    printf("&a[4]=%p\n",&a[4]);

    printf("a    =%p\n",a);
    printf("&a[0]=%p\n",&a[0]);

#endif

/**** 用指针指向a,b两个变量，通过指针运算选出值最小的那个数  ****/
#if 0

    int a,b;
    printf("请输入两个整数>:");
    scanf("%d%d",&a,&b);
    printf("a=%d b=%d\n",a,b);

    int *pa =&a;
    int *pb =&b;

    int min = (*pa<*pb)?*pa:*pb;
    printf("min=%d\n",min);

#endif

/**** 使用下标法和指针法 a[i] <=> p[i] <=> *(p+i) <=> *(a+i)  4种表示形式输出一个数组  ****/
#if 0

    int a[10]={0,1,2,3,4,5,6,7,8,9}, *pa = a;
    for (int i = 0; i < 10; i++)
    {
        printf("a[%d]= %d\n",i,a[i]);
    }
    printf("*******************\n");
    for (int i = 0; i < 10; i++)
    {
        printf("pa[%d]= %d\n",i,pa[i]);
    }

    printf("*******************\n");
    for (int i = 0; i < 10; i++)
    {
        printf("*(a+%d)= %d\n",i,*(a+i));
    }

    printf("*******************\n");
    for (int i = 0; i < 10; i++)
    {
        printf("*(pa+%d)= %d\n",i,*(pa+i));
    }

#endif

/**** 使用指针表示二维数组  ****/
#if 0

    int a[3][4];
    
    printf("a       =%p\n",a);
    printf("a[0]    =%p\n",a[0]);
    printf("*(a+0)  =%p\n",*(a+0));
    printf("&a[0][0]=%p\n",&a[0][0]);
    printf("*******************\n");

    printf("a[1]    =%p\n",a[1]);
    printf("*(a+1)  =%p\n",*(a+1));
    printf("&a[1][0]=%p\n",&a[1][0]);
    printf("*******************\n");

    printf("a[2]    =%p\n",a[2]);
    printf("*(a+2)  =%p\n",*(a+2));
    printf("&a[2][0]=%p\n",&a[2][0]);
    printf("*******************\n");

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            printf("&a[%d][%d]=%p\n",i,j,&a[i][j]);
        }
        
    }
    printf("*******************\n");

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            printf("*(a+%d)+%d=%p\n",i,j,*(a+i)+j);
        }
        
    }

#endif

/**** 分别使用字符指针和字符数组操作字符串并分析两者之间的区别
 *    字符串数字可以改变其中的值，指针类型的不可以改变   ****/
#if 0

    char *p ="hello";
    char a[] = "hello";
    printf("p=%s\n",p);
    printf("a=%s\n",a);
    a[0]='H';
    //*p = 'H';
    printf("p=%s\n",p);
    printf("a=%s\n",a);
#endif

/**** 使用字符指针数组输出星期一到星期日(Mon,Tue,Wed,Thu,Fri,Sat,Sun)  ****/
#if 0

    char *str[]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
    printf("sizeof(str)   =%d\n",sizeof(str));
    printf("sizeof(str[0])=%d\n",sizeof(str[0]));

    for (int i = 0; i < sizeof(str)/sizeof(str[0]); i++)
    {
        printf("str[%d]=%s\n",i,str[i]);
    }

#endif

/**** 使用const 指针实现三种形式的指针常量化  ****/
#if 0

    int a = 10;
    const int *pa = &a;
    //*pa = 20;
    pa++;

    int * const pb = &a;
    *pb = 20;
    //pb++;

    const int * const pc = &a;
    //*pc = 20;
    //pc++;

#endif

/**** 将一个有8个元素的数组拆分为两个数组，一个为奇数数组，一个为偶数数组  ****/
#if 0

    int str[8]={1,2,3,4,5,6,7,8};
    int a[4]={0};
    int b[4]={0};
    int index_a=0,index_b=0;

    for (int i = 0; i < 8; i++)
    {
        if((str[i]%2) == 0)
        {
            a[index_a++]=str[i];
        }
        else 
        {
            b[index_b++]=str[i];
        }
    }

    for (int i = 0; i < 4; i++)
    {
        printf("b[%d]=%d\n",i,b[i]);
    }

     for (int i = 0; i < 4; i++)
    {
        printf("a[%d]=%d\n",i,a[i]);
    }
    
    
    
    
#endif

/**** 把如下的字符串中, 把大写字母转换成小写字符, 并删除所的空格  ****/
#if 0
    char *str ="Attendees at a Trump rally in Waukesha, Wisconsin, shared who they want \
to see on the presidential ticket in 2024, with most hoping for a Donald Trump bid." ;
    char newstr[500]={0};
    char *p = str, *q = newstr;
    while(*p != '\0')
    {
        if((*p <= 'Z') && (*p >= 'A'))
        {
            *q = *p + ' ';
            p++;
            q++;
        }
        else if(*p == ' ')
        {
            p++;
        }
        else
        {
            *q = *p;
            p++;
            q++;
        }
    }
    printf("str=%s\n",str);
    printf("newstr=%s\n",newstr);
    printf("strlen(str)=%d\n",strlen(str));
    printf("strlen(newstr)=%d\n",strlen(newstr));

#endif

/**** 从键盘输入一个数字字符串，并把这个字符串转换成整数    ****/
#if 0
    char str[100]={0};
    printf("请输入一个数字字符串>:");
    scanf("%s",str);
    printf("str=%s\n",str);

    int len = strlen(str);
    printf("str=%d\n",len); 

    int num = 0;
    for (int i = 0,x; i < len; i++)
    {
        x = (str[i]-'0')*pow(10,len-1-i);
        num += x;
    }
    printf("num=%d\n",num);

#endif

/**** 从键盘输入一个数字，并把这个整数转换成字符串    ****/
#if 0
    int num = 0;
    char str[100]={0};
    printf("请输入一串整数>:");
    scanf("%d",&num);
    printf("str=%d\n",num);

    int len = 0;
    int t = num;

    for (len = 1; t / 10 != 0; t /= 10)
    {
        len++;
    }
    printf("len=%d\n",len);
    t=num;
    for (int i = 0,x; i < len; i++)
    {
        x = t%10;
        printf("x=%d\n",x);
        t=t/10;
        str[len-1-i]=x + '0';
    }
    printf("str2=%s\n",str);

#endif

/**** 调用函数实现2个数的加、减、乘、除、次方    ****/
#if 0

    int ret = add(10,5);
    printf("ret=%d\n",ret);

    ret = sub(10,5);
    printf("ret=%d\n",ret);

    ret = mul(10,5);
    printf("ret=%d\n",ret);

    ret = div(10,5);
    printf("ret=%d\n",ret);

    ret = mypow(10,5);
    printf("ret=%d\n",ret);

    

#endif

/**** 调用函数实现2个数的加、减、乘、除、次方    ****/
#if 1



#endif
    return 0;
}

int add(int x, int y)
{
    return x+y;
}

int sub(int x, int y)
{
    return x-y;
}

int mul(int x, int y)
{
    return x*y;
}

int div(int x, int y)
{
    return x/+y;
}

int mypow(int x, int y)
{
    return (int)pow(x,y);
}